package it.ictdays12.cipcip;

import java.util.ArrayList;

//import android.util.Log;

import com.twitterapime.model.MetadataSet;
import com.twitterapime.search.SearchDeviceListener;
import com.twitterapime.search.Tweet;
import com.twitterapime.search.TweetEntity;

public class CustomDeviceListener implements SearchDeviceListener {
	
	ArrayList<Pair<String,String> > myArray;
	
	public CustomDeviceListener(ArrayList<Pair<String,String> > al) {
		myArray = al;
	}
	
	public void searchCompleted() { 
		// Nothing to do.
	}

	public void searchFailed(Throwable arg0) { 
		// Nothing to do.
	}
	
	public void tweetFound(Tweet tweet) {
		
		// Log the entire tweet record.
		//Log.d("TweetRecord", tweet.toString());
		
		// Log the tweet content.
		//Log.d("Tweet", tweet.getString(MetadataSet.TWEET_CONTENT));
		
		String date = tweet.getString(MetadataSet.TWEET_PUBLISH_DATE);
		
		// Get the TweetEntity from current tweet.
		TweetEntity entity = tweet.getEntity();
		if (entity != null) {
			// Get all the hashtags from the tweet.
			TweetEntity[] tags = entity.getHashtags();
			
			for (int i = 0; i < tags.length; ++i) {
				String tag = tags[i].getString(MetadataSet.TWEETENTITY_HASHTAG);
				
				// Log tags.
				//Log.d("Tag", tag);
				
				Pair<String,String> p = new Pair<String, String>(date,tag);
				
				myArray.add(p);
			}
		}
		
		// Increments the terminated thread counter.
		++CipCipActivity.counter;
	}	
}
